package com.cblz.bd.server.core.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cblz.bd.common.core.entity.BaSecurityDataRecycleLog;
import com.cblz.bd.common.core.utils.ResultResponse;
import com.cblz.bd.common.core.utils.SearchParamsUtil;
import com.cblz.bd.server.core.annotation.AdminApiController;
import com.cblz.bd.server.core.service.BaSecurityDataRecycleLogService;
import io.vavr.Tuple3;
import io.vavr.Tuple5;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * {@code @Name:} BaSecurityDataRecycleController
 * {@code @Description: }
 * {@code @Author:} by yanjieping
 * {@code @CreateDate:} 2022/12/2 - 周五
 */
@RequiredArgsConstructor
@AdminApiController("security.dataRecycleLog")
public class BaSecurityDataRecycleLogController {

    private final BaSecurityDataRecycleLogService baSecurityDataRecycleLogService;

    @PostMapping("index")
    public ResultResponse index(@RequestBody(required = false) Map<String, Object> searchParams) {
        Tuple5 tuple5 = SearchParamsUtil.searchParamsHandle2(searchParams);
        Tuple3<Page<BaSecurityDataRecycleLog>, QueryWrapper<BaSecurityDataRecycleLog>, BaSecurityDataRecycleLog> wrapperObjectTuple3 = SearchParamsUtil.params2QueryWrapper(new BaSecurityDataRecycleLog(), tuple5);

        return new ResultResponse().data(baSecurityDataRecycleLogService.index(wrapperObjectTuple3));
    }


    @DeleteMapping("del")
    public void del(@RequestBody Map ids) {
        this.baSecurityDataRecycleLogService.delete((List) ids.get("ids"));
    }

    @GetMapping("info")
    public ResultResponse info(@RequestParam Integer id) {
        return new ResultResponse().data("data", Map.of("row", this.baSecurityDataRecycleLogService.getInfoById(id)));
    }

    @PostMapping("restore")
    public ResultResponse restore(@RequestBody Map ids) {
        this.baSecurityDataRecycleLogService.restoreByIds((List<Serializable>) ids.get("ids"));
        return new ResultResponse().message("还原数据成功");
    }

}
